package com.apop.accompany.stuff.controller;


import com.apop.accompany.stuff.entity.Stuff;
import com.apop.accompany.stuff.service.StuffService;
import com.apop.common.model.PageResult;
import com.apop.common.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 * 接口文档地址 http://localhost:8090/swagger-ui.html
 *
 * @author JiayiZheng
 * @since 2024-10-05
 */
@Api(tags = "陪护人员信息接口")
@RestController
@RequestMapping("/v3pz/stuff")
public class StuffController {

    @Resource
    private StuffService stuffService;

    @ApiOperation("根据id查询")
    @GetMapping("/info")
    @ResponseBody
    public Result getById(@ApiParam(value = "ID", required = true) @RequestParam Integer id) {
        return Result.success(stuffService.getById(id)) ;
    }

    @ApiOperation("列表查询")
    @GetMapping("/list")
    @ResponseBody
    public Result list(@ApiParam(value = "当前页码") @RequestParam(name = "pageNum")  Integer pageNum,
                       @ApiParam(value = "页面数量") @RequestParam(name = "pageSize") Integer pageSize) {
        PageResult pageList = stuffService.getList(pageNum,pageSize);
        return Result.success(pageList);
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    @ResponseBody
    public Result save(@ApiParam(value = "记录对象", required = true) @RequestBody Stuff stuff) {
        return stuffService.save(stuff) ? Result.success("操作成功"):Result.success("操作失败") ;
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    @ResponseBody
    public Result update(@ApiParam(value = "记录对象", required = true) @RequestBody Stuff stuff) {
        return stuffService.update(stuff) > 0 ? Result.success("操作成功"):Result.success("操作失败") ;
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    @ResponseBody
    public Result delete(@ApiParam(value = "ID", required = true) @RequestParam Integer id) {
        return stuffService.deleteById(id) > 0 ? Result.success("操作成功"):Result.success("操作失败") ;
    }

    @ApiOperation("批量删除")
    @PostMapping("/batchDelete")
    @ResponseBody
    public Result batchDelete(@ApiParam(value = "ID 列表", required = true) @RequestBody List<Integer> ids) {
        int count = stuffService.deleteBatch(ids);
        return count > 0 ? Result.success("操作成功") : Result.success("操作失败");
    }

    @GetMapping("/photoList")
    @ResponseBody
    public Result photoList(){
        List list = new ArrayList<>();
        list.add("/image/avatar.jpg");
        list.add("/image/avatar_def.png");
        return Result.success(list);
    }

}
